﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Peekaboo2008.dao;
using Peekaboo2008.common;

namespace Peekaboo2008.view
{
    public partial class FormXuatBanHangHoaTimKiem : Form
    {
        private DataTable dbDanhSachPhieuhang;
        public FormXuatBanHangHoaTimKiem()
        {
            InitializeComponent();
            initLoaiHoaDon();
        }

        private void initLoaiHoaDon(){
            cbbLoaiHoaDon.Items.Add("Tất cả");
            cbbLoaiHoaDon.Items.Add("Xuất");
            cbbLoaiHoaDon.Items.Add("Nhập");
            cbbLoaiHoaDon.SelectedIndex = 0;
        }

        private void timKiem()
        {
            String Opts = cbbLoaiHoaDon.SelectedIndex.ToString();
            String IgnoreDateTime = ckbTatCa.Checked ? "1" : "0";
            String From = dtpTuNgay.Value.ToShortDateString();
            String To = dtpDenNgay.Value.ToShortDateString();

            dbDanhSachPhieuhang = PhieuNhapXuatDAO.GetByFromTo(Constants.USER_LOGIN.MaChiNhanh,Opts, IgnoreDateTime, From, To);
            if (dbDanhSachPhieuhang == null)
            {
                MessageBox.Show(this, "Danh sách không tồn tại", "Thông báo", MessageBoxButtons.OK);
            }
            else
            {
                grvDanhSachPhieuHang.DataSource = dbDanhSachPhieuhang;
            }
        }

        private void btnTimKiem_Click(object sender, EventArgs e)
        {
            timKiem();
        }

        private void ckbTatCa_CheckedChanged(object sender, EventArgs e)
        {
            if(ckbTatCa.Checked){
                dtpDenNgay.Enabled = false;
                dtpTuNgay.Enabled = false;
            }else{
                dtpDenNgay.Enabled = true;
                dtpTuNgay.Enabled = true;
            }
        }

        private void FormXuatBanHangHoaTimKiem_KeyDown(object sender, KeyEventArgs e)
        {
            switch (e.KeyCode)
            {
                case Keys.F6:
                    timKiem();
                    break;
                case Keys.F7:
                    this.Dispose();
                    break;

            }
        }
    }
}
